<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2022/5/16
  Time: 14:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>相关文档</title>

</head>
<link rel="stylesheet" type="text/css" href="/css/page.css">
<script type="text/javascript" src="/js/page.js"></script>
<body>
<div>
    <h1 class="text-center">相关文档</h1>
    <a href="javascript:" id="add">增加</a>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>标题</th>
            <th>作者</th>
            <th>发布者</th>
            <th>发布日期</th>
            <th>备注</th>
            <th>操作</th>

        </tr>
        </thead>
        <tbody id="table">

        </tbody>

    </table>
    <div class="pageTest"></div>
</div>
</body>
<script type="text/javascript">
    $('.pageTest').page({
        leng: 1,//分页总数
        activeClass: 'activP' , //active 类样式定义
        clickBack:function(page){
            console.log(page)
        }
    })
    // $('.pageTest').setLength(10)

    $(function () {
        $.ajax({
            url:"/eme/findByPage/1/100",
            method:"get",
            dataType:"json",
            success:function (data) {

                for (var i=0;i<data.list.length;i++){
                    var text="<tr><td>"+data.list[i].tite+"</td> <td>"+data.list[i].author+"</td> <td>"+data.list[i].publisher+"</td> <td>"+data.list[i].gmt_modified+"</td> <td>"+data.list[i].remarks+"</td><td><input id='"+data.list[i].id+"' type='hidden' value='"+data.list[i].id+"'><a href='javascript:'>编辑</a>--<a href='javascript:'>删除</a></td>"
                    $("#table").append(text)

                    $("#"+data.list[i].id).next("a").click(function () {
                        var listid=$(this).prev().val()
                        $("#content1").empty()
                        $("#content2").empty()
                        $("#content2").load("relatedDocumentsedit/"+listid)
                    })


                    $("#"+data.list[i].id).next("a").next("a").click(function () {
                        var listid=$(this).prev().prev().val()
                        var searchMap = {
                           "id":listid
                        };
                        var msg = "您真的确定要删除吗？！";
                        if (confirm(msg)==true) {
                            $.ajax({
                                url: '/eme/addsfile',
                                type: 'delete',
                                dataType: 'json',
                                data: JSON.stringify(searchMap),
                                contentType: "application/json",
                                success: function () {
                                    alert("删除成功")
                                    window.location.href = "troubleRemoval";

                                },
                                error: function () {
                                    alert("删除失败")
                                }
                            })
                        }else {

                        }
                    })

                }
            }


        })
    })
    $("#add").click(function () {
        $("#content1").empty()
        $("#content2").empty()
        $("#content2").load("relatedDocumentsadd")
    })

</script>
</html>
